console.log('Server Config File: ' + __filename);
var args = util.parseCommandLine();
var PATH = util.normalizePath;

// UserCenter服务器域名地址
var UC_HOST  = 'http://'+(args.uc_host || 'ucx.sf.katcin.com' || 'pcas.sf.katcin.com');

// DSP域名地址
var DSP_HOST = 'http://'+(args.app_host || 'pdsp.sf.katcin.com');

// DSP一般业务管理Mongo地址
var DB_APP_HOST  = '192.168.10.250';
// DSP管理后台
var DB_MASTER_HOST = '192.168.10.250';
var DB_ADMIN_HOST = DB_APP_HOST;

var DIR_LOG = process.env.DIR_LOG;
var DIR_RUN = process.env.DIR_RUN;

// prot config
var ports;
if (process.platform == 'linux')
{
	// linux bind as unix socket
	ports = {
		proxy: `unix:/${DIR_RUN}/socket.proxy`,
		http: `unix:/${DIR_RUN}/socket.http`,
		app_api: `unix:/${DIR_RUN}/socket.app_api`,
		app_pub: `unix:/${DIR_RUN}/socket.app_pub`,
		app_uc: `unix:/${DIR_RUN}/socket.app_uc`,
		app_ws: `unix:/${DIR_RUN}/socket.app_ws`,
		app_product: `unix:/${DIR_RUN}/socket.app_product`,
		admin_api: `unix:/${DIR_RUN}/socket.admin_api`,
		admin_uc: `unix:/${DIR_RUN}/socket.admin_uc`,
		admin_ws: `unix:/${DIR_RUN}/socket.admin_ws`,
		server_admin: `unix:/${DIR_RUN}/socket.admin_server`
	};
}
else
{
	// window develop bind
	ports = {
		proxy: 8085,
		http: 6412,
		app_api: 6413,
		app_pub: 6421,
		app_uc: 6414,
		app_ws: 6415,
		app_product: 6416,
		admin_api: 6417,
		admin_uc: 6418,
		admin_ws: 6419,
		server_admin: 9181
	}
}

var config = {
	RELEASE: false,
	TEST_ENVIRONMENT: false,
	RADON: {
		// child process user
		// USER: 'www-data',
		// GROUP: 'www-data',
		USER: 'heng',
		GROUP: 'staff',

		APP_NAME: process.env.APP_NAME,
		PID_FILE: PATH(`/${DIR_RUN}/pid`),
		LOG_APP_FILE: PATH(`/${DIR_LOG}/app_`),
		LOG_ERR_FILE: PATH(`/${DIR_LOG}/error_`),
		LOG_FRONT_FILE: PATH(`/${DIR_LOG}/front_`),
		LOG_REQUEST_FILE: PATH(`/${DIR_LOG}/socket_`),

		SESSIONS: {
			APP: `/${DIR_RUN}/sessions.data`,
			MASTER: `/${DIR_RUN}/sessions_master.data`,
			ADMIN: `/${DIR_RUN}/sessions_admin.data`
		},

		CLUSTER_QUEUE_MAX: 5,
		CLUSTER_QUERY_MEM: 2048,
		CLUSTER_QUERY_THREAD: 2,

		CLUSTER_APP_MAX: 5,
		CLUSTER_APP_MEM: 2048,
		CLUSTER_APP_THREAD: 2,

		PORTS: {
			APP: {
				PROXY: ports.proxy,
				HTTP: ports.http,
				API: ports.app_api,
				PUB: ports.app_pub,
				UCAPI: ports.app_uc,
				PRODUCT: ports.app_product,
				WEBSOCKET: ports.app_ws
			},
			ADMIN: {
				API: ports.admin_api,
				UCAPI: ports.admin_uc,
				WEBSOCKET: ports.admin_ws
			},
		},
		DEBUG: {
			APP: 59,
			MASTER: 59,
			ADMIN: 59
		},
		ADMIN_SERVER: {
			"id": "DSP",
			"password": false,
			"listen": ports.server_admin,
			'dump_path': PATH(`/${DIR_RUN}/heap/`)
		}
	},
	// 程序设置参数
	APP: {
		USER: {},
		HTTP_TIMEOUT: 300000 * 4,
		REQUEST_TIMEOUT: 1800,
		// 最高级账号
		MASTER_ACCOUNT:{
			"id": -1,
			"name": "广州舜飞科技有限公司"
		},
		// 邮件配置
		MAIL: {
			// 默认配置
			DEFAULT:{
				"smtp": {
					host: "smtp.exmail.qq.com",
					port: 465,
					secure: true, // use SSL
					auth: {
						user: 'fortest@sunteng.com',
						pass: 'Biddingx2017'
					}
				}
			}
		}
	},
	COOKIE: {
		APP: '_DSP_APP_SID'
	},
	// UC API 设置
	UC: {
		'api': {
			'url': UC_HOST + '/api/uc_core/comm',
			'id': 2,
			'name': 'DSP',
			'token': 'm2j#opUz&8zEJMAuWu1lJ#fx',
			'hasAgent': 2
		},
		'host': UC_HOST,
		'create': DSP_HOST + '/addAccount.html',
		'login': '/api/cas/login',
		'logout': '/logout.html'
	},
	//审核系统的产品配置
	AUDIT: {
		'pid':1,
		'token': 'abcdefg',
		'url':'http://audit.sf.katcin.com/audit/api/{module}/{method}',
	},
	// 数据库配置
	DB: {
		// 普通后台数据库配置
		APP: {
			MAX_QUEUE: 50,
			// 会话数据库配置
			SESSION: {
				HOST: DB_APP_HOST+'/dsp_personal_config',
				// HOST: DB_APP_HOST+'/pdsp_config',
				COLLECTION: 'session_app'
			}
			// 主数据库地址
			,MAIN: DB_APP_HOST + '/dsp_personal_online'
			// ,MAIN: DB_APP_HOST + '/pdsp'
			// 日志数据库地址
			,LOG: DB_APP_HOST + '/dsp_personal_log'
			// ,LOG: DB_APP_HOST + '/pdsp_log'
			// 配置信息数据库地址
			,CONFIG: DB_APP_HOST + '/dsp_personal_config'
			// ,CONFIG: DB_APP_HOST + '/pdsp_config'
			// Mysql数据库地址
			,MYSQL: {
				host: '192.168.10.60'
				,port: 3306
				,user: 'root'
				,password: 'root'
				,database: 'clicki_v2'
			}
		}
		// 系统管理后台数据库配置
		,ADMIN: {
			MAX_QUEUE: 50,

			// 会话数据库配置
			SESSION: {
				// HOST: DB_ADMIN_HOST+'/dsp_config',
				HOST: DB_ADMIN_HOST+'/pdsp_config',
				COLLECTION: 'session_admin'
			}
			// 主数据库地址
			// ,MAIN: DB_ADMIN_HOST + '/dsp_personal_online'
			,MAIN: DB_ADMIN_HOST + '/pdsp'
			// 日志数据库地址
			// ,LOG: DB_ADMIN_HOST + '/dsp_personal_log'
			,LOG: DB_ADMIN_HOST + '/pdsp_log'
			// 配置信息数据库地址
			// ,CONFIG: DB_ADMIN_HOST + '/dsp_personal_config'
			,CONFIG: DB_ADMIN_HOST + '/pdsp_config'
			// Mysql数据库地址
			,MYSQL: {
				host: '192.168.10.60'
				,port: 3306
				,user: 'root'
				,password: 'root'
				,database: 'clicki_v2'
			}
		}
	}
	,DATACENTER_SERVER: "http://192.168.10.251:50002/query/statistic"
	,DATACENTER_TIMEOUT: 300000
	,HOST: {
		UC: UC_HOST
		,DSP: DSP_HOST
	}
	,PATH: {
		FILE: PATH('/../data/')	//文件保存路径, 如上传的文件存放
		,HTTP_UPLOAD: PATH('/../data/tmp/')
		,VERSION_FILE: PATH('/../web/version.txt')
		,OEM_ROOT: false
		,OFFLINE: {
			CUSTOM: PATH('/../data/offline/custom/'),
			SCHEDULE: PATH('/../data/offline/schedule/'),
		}
	}
	// 程序所需要的命令.
	,BIN: {
		// 命令运行超时时间, 单位: 秒
		TIMEOUT: 10
		// 压缩的命令路径.
		,UNZIP: PATH('/bin/external/7z x {file} -o{output}')
		,ZIP: PATH('/bin/external/7z a -w {path} {files}')

		// 截图的工具路径
		,CUTYCAPT: PATH('/bin/external/capture {width} {height} {delay} \"{output}\" \"{url}\"')

		// 视频截图
		,CUTYVIDEO: PATH('/bin/external/ffmpeg \"{output}\" \"{path}\"')
		// 视频转换
		,CONVERTVIDEO: PATH('/bin/external/convert \"{path}\" \"{output}\"')

		// 视频或图片信息
		,VIDEOJSONINFO: PATH('/bin/external/ffprobe \"{path}\"')

		// tail log command
		,TAIL: 'tail -n {line} {file} > {target}'
	}
	// 展示代码CDN
	,PREVIEW_SCRIPT_CDN: '//cdn.scdng.com/'
	,HTTP_PROXY:  {
		'host': '192.168.10.250',
		'port': '7777'
	}
	,CAMPAIGN_CODE: {
		"agent_url": "http://dsp_masky.server/whisky/j",
		"monitor_url": "http://dsp_masky.server/masky/ana/sweety/x.gif",
		"creative_url": "http://dsp.server"
	}
	//todo 统计需要提供的接口
	//取活动或账号消耗费用实时接口.
	,COST: {
	
	}
	,EXCHANGE_CONF: {
		10100: {
			auth: {
				id: 21,
				token: "4b300e739645ef7f80146e449bfeee04f858144fe2f67bf6"
			}
			,url: "http://sspmbv.server/api/"
			,api: {
				spotSync: 'slot/sync',
				dealSync: 'order/sync'
			}
		},
		10013: {
			auth: {
				id: 3,
				token: "c8569d77120648f1a2204fa143bde450"
			}
			,url: "http://sspnew.server/api/"
			,api: {
				spotSync: 'slot/sync',
				dealSync: 'order/sync'
			}
		}
	}
};
